package com.ddtech.business.vrTask.controller;

import com.ddtech.annotation.AnonymousAccess;
import com.ddtech.business.room.entity.RoomUser;
import com.ddtech.business.room.service.RoomUserService;
import com.ddtech.business.vrTask.entity.VrTask;
import com.ddtech.business.vrTask.query.VrTaskQuery;
import com.ddtech.business.vrTask.service.VrTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @version v1.0
 * @ClassName:VrTaskController description：
 * @author:wei_zhang(xiao)
 * @date: 2024-11-15 13:34
 */
@Api(tags = "业务-任务管理")
@RestController
@RequestMapping("/vrTask")
public class VrTaskController {

    @Autowired
    private VrTaskService vrTaskService;

    @Autowired
    private RoomUserService roomUserService;

//    @Autowired
//    private SimpMessagingTemplate messagingTemplate;


    @GetMapping(value = "/check")
    @AnonymousAccess
    public ResponseEntity check() {
        return new ResponseEntity(true,HttpStatus.OK);
    }

    @GetMapping(value = "/checkOnline")
    public ResponseEntity checkOnline() {
        return new ResponseEntity(true,HttpStatus.OK);
    }

    @ApiOperation(value = "创建任务")
    @PostMapping(value = "/create")
    public ResponseEntity create(@RequestBody VrTask vrTask) {
        vrTaskService.create(vrTask);
        return new ResponseEntity(true,HttpStatus.OK);
    }

    @ApiOperation(value = "创建任务")
    @GetMapping(value = "/del/{id}")
    public ResponseEntity del(@PathVariable String id) {
        vrTaskService.del(id);
        return new ResponseEntity(true,HttpStatus.OK);
    }

    @ApiOperation(value = "查询任务列表")
    @GetMapping(value = "/page-list")
    public ResponseEntity getPageList(VrTaskQuery vrTaskQuery) {
        return new ResponseEntity(vrTaskService.pageList(vrTaskQuery), HttpStatus.OK);
    }

    @ApiOperation(value = "查询任务列表")
    @GetMapping(value = "/list")
    public ResponseEntity getList(VrTaskQuery vrTaskQuery) {
        return new ResponseEntity(vrTaskService.list(vrTaskQuery), HttpStatus.OK);
    }

    @ApiOperation(value = "查询任务包含房间列表")
    @GetMapping(value = "/taskWithRoom")
    public ResponseEntity taskWithRoom(VrTaskQuery vrTaskQuery) {
        return new ResponseEntity(vrTaskService.taskWithRoom(vrTaskQuery), HttpStatus.OK);
    }

    @ApiOperation(value = "查询任务包含房间列表")
    @GetMapping(value = "/taskWithRoomNoPage")
    public ResponseEntity taskWithRoomNoPage(VrTaskQuery vrTaskQuery) {
        return new ResponseEntity(vrTaskService.taskWithRoomNoPage(vrTaskQuery), HttpStatus.OK);
    }


    @PostMapping("/joinRoom")
    @AnonymousAccess
    public ResponseEntity roomData(@RequestBody RoomUser roomUser) {
        roomUserService.joinRoom(roomUser);
        VrTaskQuery vrTaskQuery = new VrTaskQuery();
        //messagingTemplate.convertAndSend("/topic/roomData",vrTaskService.taskWithRoom(vrTaskQuery));
        return new ResponseEntity(true, HttpStatus.OK);
    }
}
